package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketTopic;
import com.cskaoyan.market.db.domain.MarketTopicExample;
import com.cskaoyan.market.db.mapper.MarketTopicMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cx
 * @date 2023/4/3 0:48
 * @Version 1.0
 */
@Service
public class WxTopicServiceImpl implements WxTopicService{

    @Autowired
    MarketTopicMapper marketTopicMapper;


    @Override
    public List<MarketTopic> list(Integer page, Integer limit) {

        MarketTopicExample topicExample = new MarketTopicExample();
        topicExample.or().andDeletedEqualTo(false);
        PageHelper.startPage(page,limit);
//        List<MarketTopic> marketTopics = marketTopicMapper.selectByExample(topicExample);
        List<MarketTopic> marketTopics = marketTopicMapper.selectByExample(topicExample);
        return marketTopics;

       // List<WxMarketTopicVo> result = new ArrayList<>();

        /*for (MarketTopic marketTopic : marketTopics) {
            WxMarketTopicVo marketTopicVo = new WxMarketTopicVo();
            marketTopicVo.setId(marketTopic.getId());
            marketTopicVo.setPicUrl(marketTopic.getPicUrl());
            marketTopicVo.setPrice(marketTopic.getPrice());
            marketTopicVo.setReadCount(marketTopic.getReadCount());
            marketTopicVo.setSubtitle(marketTopic.getSubtitle());
            marketTopicVo.setTitle(marketTopic.getTitle());
            result.add(marketTopicVo);
        }*/

    }

    @Override
    public Map<String , Object> detail(Integer id) {
        HashMap<String, Object> resultMap = new HashMap<>();
        MarketTopicExample topicExample = new MarketTopicExample();
        topicExample.or().andIdEqualTo(id);

        MarketTopic topic = marketTopicMapper.selectOneByExampleWithBLOBs(topicExample);
        resultMap.put("topic",topic);
        resultMap.put("goods",topic.getGoods());
        return resultMap;
    }

    @Override
    public List<MarketTopic> related(Integer id) {
        MarketTopicExample topicExample = new MarketTopicExample();
        topicExample.or().andDeletedEqualTo(false).andIdNotEqualTo(id);
        PageHelper.startPage(1, 5);
        List<MarketTopic> result = marketTopicMapper.selectByExampleSelective(topicExample);
//        for (MarketTopic topic : result) {
//            if(id.equals(topic.getId())){
//                result.remove(topic);
//            }
//        }
        return result;
    }
}
